<template>
  <div class="app-container">
    <div class="filter-container filter-container-left">
      <el-form class="form_search flex_box_between" :inline="true" label-width='90px'>
        <el-form-item label="用户名：">
          <el-input v-model="queryParam.username" placeholder="请输入用户名" clearable />
        </el-form-item>
        <el-form-item label="账号：">
          <el-input v-model="queryParam.mobile" placeholder="请输入账号" clearable />
        </el-form-item>
        <el-form-item label="用户类型：">
          <el-select v-model="queryParam.user_type" placeholder="请选择用户类型">
            <el-option
              v-for="item in userTypes"
              :key="item.value1"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="操作类型：">
          <el-select v-model="queryParam.from_type" placeholder="请选择操作类型">
            <el-option
              v-for="item in optionsType"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="收支类型：">
          <el-select v-model="queryParam.sgin_type" placeholder="请选择收支类型">
            <el-option
              v-for="item in optionsIncome"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <el-form class="form_search" :inline="true" label-width='90px'>
        <el-form-item label="操作时间：">
          <el-date-picker
            v-model="time"
            type="datetimerange"
            range-separator="至"
            start-placeholder="开始时间"
            end-placeholder="结束时间"
            value-format="yyyy-MM-dd HH:mm:ss"
            class="filter-item form-search-input1"
            @change='timeChange'
            :picker-options="pickerOptions">
          </el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button class="filter-item search" type='primary' icon="iconfont icon-sousuo" @click="handleSearch">查询</el-button>
          <el-button class="filter-item search" type="info" plain icon="iconfont icon-zhongzhi" @click="handleRefresh">重置</el-button>
          <el-button class="filter-item search" icon="iconfont icon-daochu" @click="handleExport">导出</el-button>
        </el-form-item>
      </el-form>
    </div>
    <el-table
      :data="data"
      style="width: 100%;margin-bottom: 20px;"
      row-key="id"
      border
      default-expand-all
      :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
    >
      <!-- <el-table-column prop="id" label="序号" width='80' align='center'/> -->
      <el-table-column label="用户名"  align='center'>
        <template slot-scope="item">
          <p v-if="item.row.user_info">{{item.row.user_info.username || item.row.user_info.mobile}}</p>
        </template>
      </el-table-column>
      <el-table-column prop="user_info.mobile" label="账号" align='center'/>
      <el-table-column label="用户类型"  align='center'>
        <template slot-scope="item">
          <p>{{item.row.user_type==1?'个人':item.row.user_type==2?'企业':''}}</p>
        </template>
      </el-table-column>
      <el-table-column label="操作类型"  align='center'>
        <template slot-scope="item">
          <p>{{getFromType(item.row)}}</p>
        </template>
      </el-table-column>
      <el-table-column label="金额" prop='number' align='center'/>
      <el-table-column label="收支类型" align='center'>
        <template slot-scope="item">
          {{item.row.sign==1?'收入':'支出'}}
        </template>
      </el-table-column>
      <el-table-column prop="create_time" label="操作时间" align='center'/>
    </el-table>
    <el-pagination
      background
      class="pagination-container"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="paginate.current"
      :hide-on-single-page='isHideSingle'
      :page-sizes="paginate.sizes"
      :page-size="paginate.limit"
      :layout="paginate.layout"
      :total="paginate.total"/>
  </div>
</template>

<script>
import formOperate from '@/layout/mixin/formOperate'
import { export2Excel } from '@/utils/excel'
export default {
  name: 'Index',
  mixins: [formOperate],
  data() {
    return {
      url:'/user/admin/Records',
      queryParam: {
        username: '',
        mobile:'',
        user_type:'',
        from_type:'',
        sgin_type:'',
        start_time:'',
        end_time:'',
        page:1,
        page_size:10
      },
      time:'',
      defaultQueryParam:['page','page_size','status'],
      optionsType:[
        {value:'1',label:'红包'},
        {value:'2',label:'提现'},
        {value:'3',label:'邀请'},
        {value:'4',label:'保到岗'}
      ],
      userTypes: [
        {value:'',label:'所有'},
        {value:1,label:'个人'},
        {value:2,label:'企业'}
      ],
      optionsIncome:[
        {value:'0',label:'出账'},
        {value:'1',label:'入账'}
      ],
      froms:[
        {label:'注册账号',value:1},
        {label:'发布简历',value:2},
        {label:'浏览岗位',value:3},
        {label:'邀请注册',value:30},
        {label:'发布简历',value:31},
        {label:'认证企业',value:32},
        {label:'发布职位',value:33},
        {label:'薪资结算',value:40},
        {label:'提现',value:100},
        {label:'拒绝提现返回用户余额',value:101}
      ],
    }
  },
  methods: {
    // 操作类型
    getFromType(item) {
      let idx = this.froms.findIndex(res=>{
        return res.value == item.from_type
      })
      return idx>-1?this.froms[idx].label:''
    },
    // 导出
    handleExport() {
      let columns = [
        {title:'用户名',key:'name'},
        {title:'账号',key:'mobile'},
        {title:'用户类型',key:'type'},
        {title:'操作类型',key:'from_type'},
        {title:'金额',key:'number'},
        {title:'收支类型',key:'sign'},
        {title:'操作时间',key:'time'}
      ]
      let list = []
      this.data.forEach(res=>{
        list.push({
          name:res.user_info?(res.user_info.username || res.user_info.mobile):'',
          mobile:res.user_info?res.user_info.mobile:'',
          type:res.user_type==1?'个人':res.user_type==2?'企业':'',
          from_type:this.getFromType(res),
          number:res.number,
          sign:res.sign==1?'收入':'支出',
          time:res.create_time
        })
      })
      export2Excel(columns,list,'收支流水数据')
    },
  }
}
</script>
<style>
  .details .el-dialog__body{
    height: 700px;
    overflow-y: auto;
  }
</style>
<style lang="scss" scoped>
  .backUp{
    flex:1;
    min-width: 0;
    text-align: left;
    margin-bottom:10px;
  }
  .title{
    font-size: 16px;
    margin-bottom:10px;
  }
  .info{
    line-height: 30px;
  }
  .img_box{
    text-align: center;
  }
  .job_list{
    border:1px solid #eee;
    padding: 10px;
    border-radius: 4px;
  }
</style>